<?php

class payment_driver_bnftsocl extends a_base_payment_driver {

    private $selection = NULL;
    private $account_num = NULL;
    private $allowed_cards = array(
        'bnft' => 'Benefit Card',
        'socl' => 'Social Assistance Card'
    );

    public function __construct(stdClass $driver_data_row) {
        parent::__construct($driver_data_row);
    }

    public function validate_payment() {

        $selection = $this->_post("bnftsocl_radio");
        $card_number = $this->_post("bnftsocl_text");
        if ($selection) {
            $this->selection = $selection;
            if ($card_number) {
                $this->account_num = $card_number;
                if ($selection === 'bnft' || $selection === 'socl') {
                    return $this->allowed_cards[$selection];
                } 
            } else {
                $this->error_msg = "Invalid " . $this->allowed_cards[$selection] . " Card Number";
                return FALSE;
            }
        } else {
            $this->error_msg = "You must select either <strong>Benefit Card</strong> or <strong>Social Assistance</strong>";
            return FALSE;
        }
    }

    public function write_transaction() {
        $this->db()
                ->set('order_id', $this->order_object->id)
                ->set('card_type', $this->allowed_cards[$this->selection])
                ->set('account_num', $this->account_num)
                ->insert('payment_driver_bnftsocl_transaction');
    }

    public function get_payment_transactional_info(order_m_order $obj) {
        $query = $this->db()->where("order_id", $obj->id)->get("payment_driver_bnftsocl_transaction");
        if ($query->num_rows()) {
            $data = $query->row();
            return "" . $data->card_type." [ ".$data->account_num." ]";
        } else {
            return "n/a";
        }
    }

}

?>